<template>
  <div class="GReceiveList">
    <filterPanel filterName="GAssessmentListFilter" filterTitle="研判收件查询" :filterList="filterData"
                 @filterChange="filterChange"></filterPanel>
    <tablePanel tableName="GAssessmentListTable" :tableLoading="loading" tableTitle="研判收件列表" :tableList="tableList"
                :tableData="tableData" :total="total" :currentPage="form.page_start" :pageSize="form.page_size"
                @sizeChange="sizeChange" @pageChange="pageChange" @tableClick="tableClick">
      <zy-button @click="exportExcel">导出列表</zy-button>
    </tablePanel>
  </div>
</template>

<script>
import {mapGetters} from "vuex";

export default {
  name: "GReceiveList",
  props: {},
  data() {
    return {
      currentPath: '/ypreceive_list',
      filterData: [
        {
          title: '收件编号',
          name: 'logistics_id',
          type: 'input',
          value: '',
          maxlength: '100',
          isShow: true,
          isSelected: true
        },
        {
          title: '收件单号',
          name: 'logistics_no',
          type: 'input',
          value: '',
          maxlength: '100',
          isShow: true,
          isSelected: true
        },
        {
          title: '承运物流企业',
          name: 'logistics_enterprise',
          type: 'input',
          value: '',
          maxlength: '100',
          isShow: true,
          isSelected: true
        },
        {
          title: '企业类型',
          name: 'company_type',
          type: 'select',
          optionList: [
            {label: '全部', value: ''},
            {label: '物流', value: 0},
            {label: '快递', value: 1},
            {label: '分拣中心', value: 2},
          ],
          value: '',
          isShow: true,
          isSelected: true
        },
        // {
        // 	title: '送达站点',
        // 	name: 'arrive_region',
        // 	type: 'cascader',
        // 	value: [],
        // 	optionList: [],
        // 	optionProps: {
        // 		checkStrictly: true,
        // 		value: 'value',
        // 		label: 'label',
        // 		children: 'children'
        // 	},
        // 	isShow: true,
        // 	isSelected: true
        // },
        {
          title: '送达站点',
          name: 'address',
          type: 'input',
          value: '',
          isShow: true,
          isSelected: true
        },
        {
          title: '寄件人',
          name: 'sender',
          type: 'input',
          value: '',
          maxlength: '20',
          isShow: true,
          isSelected: true
        },
        {
          title: '寄件人联系方式',
          name: 'sender_phone',
          type: 'input',
          value: '',
          maxlength: '11',
          isShow: true,
          isSelected: true
        },
        // {
        // 	title: '揽件员',
        // 	name: 'employee_name',
        // 	type: 'input',
        // 	value: '',
        // 	maxlength: '20',
        // 	isShow: true,
        // 	isSelected: true
        // },
        {
          title: '收件人',
          name: 'recipients',
          type: 'input',
          value: '',
          maxlength: '20',
          isShow: true,
          isSelected: true
        },
        {
          title: '收件人联系方式',
          name: 'recipients_phone',
          type: 'input',
          value: '',
          maxlength: '11',
          isShow: true,
          isSelected: true
        },
        // {
        // 	title: '是否可疑',
        // 	name: 'suspicious',
        // 	type: 'select',
        // 	optionList: [
        // 		{label: '全部', value: ''},
        // 		{label: '正常件', value: 0},
        // 		{label: '可疑件', value: 1},
        // 	],
        // 	value: '',
        // 	isShow: true,
        // 	isSelected: true
        // },
        // {
        // 	title: '收件客户类型',
        // 	name: 'isprotocol',
        // 	type: 'select',
        // 	optionList: [
        // 		{label: '全部', value: ''},
        // 		{label: '普通客户', value: 0},
        // 		{label: '协议客户', value: 1},
        // 	],
        // 	value: '',
        // 	isShow: true,
        // 	isSelected: true
        // },
        {
          title: '收件时间',
          name: 'registration_date',
          type: 'date',
          value: [],
          rangeType: 'month',
          isShow: true,
          isSelected: true
        },
      ],
      form: {
        logistics_id: '',
        logistics_no: '',
        logistics_enterprise: '',
        company_type: '',
        arrive_region: [],
        sender: '',
        sender_phone: '',
        employee_name: '',
        recipients: '',
        recipients_phone: '',
        suspicious: '',
        isprotocol: '',
        registration_date: [],
        page_start: 1,
        page_size: 10,
        address: ''
      },
      loading: false,
      tableList: [
        {
          title: '收件编号',
          width: 160,
          name: 'logistics_id',
          isShow: true,
          isSelected: true
        },
        {
          title: '收件单号',
          width: 160,
          name: 'logistics_no',
          isShow: true,
          isSelected: true
        },
        {
          title: '承运物流企业',
          width: 200,
          name: 'company_name',
          isShow: true,
          isSelected: true
        },
        {
          title: '企业类型',
          width: 120,
          name: 'company_type_str',
          isShow: true,
          isSelected: true
        },
        {
          title: '收件地址',
          width: 180,
          name: 'receive_communicate_address',
          isShow: true,
          isSelected: true
        },
        {
          title: '寄件人',
          width: 120,
          name: 'post_communicate_name',
          isShow: true,
          isSelected: true
        },
        {
          title: '寄件人联系方式',
          width: 160,
          name: 'post_communicate_mobile',
          isShow: true,
          isSelected: true
        },
        // {
        // 	title: '揽件员',
        // 	width: 120,
        // 	name: 'employee_name',
        // 	isShow: true,
        // 	isSelected: true
        // },
        {
          title: '收件人',
          width: 120,
          name: 'match_communicate_name',
          isShow: true,
          isSelected: true
        },
        {
          title: '收件人联系方式',
          width: 160,
          name: 'match_communicate_phone',
          isShow: true,
          isSelected: true
        },
        // {
        // 	title: '是否可疑',
        // 	width: 120,
        // 	name: 'is_dubious_str',
        // 	isShow: true,
        // 	isSelected: true
        // },
        // {
        // 	title: '收件客户类型',
        // 	width: 120,
        // 	name: 'customer_id',
        // 	isShow: true,
        // 	isSelected: true
        // },
        {
          title: '收件时间',
          width: 200,
          name: 'create_time',
          isShow: true,
          isSelected: true
        },
        {
          title: '操作',
          width: 150,
          name: 'handler',
          fixed: 'right',
          btns: [
            {
              type: 'look',
              name: '详情'
            },
          ],
          isSelected: true
        }
      ],
      tableData: [],
      total: 0,
      download_url: '',
      ypList: [],
      showModel: false,
      receive_info: '',
      logistics_id: ''
    };
  },
  computed: {
    postData() {
      let data = {
        // logistics_type  1 ：寄件 2 收件
        logistics_type: 2,
        logistics_id: this.form.logistics_id,
        logistics_no: this.form.logistics_no,
        logistics_enterprise: this.form.logistics_enterprise,
        company_type: this.form.company_type,
        arrive_region: this.form.arrive_region.length ? this.form.arrive_region[this.form.arrive_region.length - 1] : '',
        sender: this.form.sender,
        sender_phone: this.form.sender_phone,
        employee_name: this.form.employee_name,
        recipients: this.form.recipients,
        recipients_phone: this.form.recipients_phone,
        suspicious: this.form.suspicious,
        isprotocol: this.form.isprotocol,
        address: this.form.address,
        pagination: {
          page_start: this.form.page_start,
          page_size: this.form.page_size
        }
      };
      if (this.form.registration_date && this.form.registration_date.length > 0) {
        data.create_time_start = this.form.registration_date[0] / 1000;
        data.create_time_end = this.form.registration_date[1] / 1000;
      }
      return data;
    },
    ...mapGetters(['authority', 'getAreaList']),
    isDetail() {
      return this.authority[this.currentPath] && this.authority[this.currentPath].i;
    },
  },
  watch: {},
  components: {},
  methods: {
    submitYp() {
      let bj_name = this.ypList.find(bj => this.person_bj_type == bj.value).name
      this.$confirm(`确定将原收件信息【${this.person_name}】研判为【${bj_name}】`).then(() => {
        this.$axios.post(this.$api.admin_bj_person, {}).then(res => {
          let {code, msg, data} = res;
          if (code == 200) {
            this.$message.success('研判成功');
            this.getData()
          } else {
            this.$message.error(msg);
          }
        }).catch(ret => {
          this.$message.error(ret.msg || '服务繁忙，请稍后再试');
        });
      })
    },
    setFilterData(val, nameList) {
      for (let item of this.filterData) {
        if (nameList.indexOf(item.name) !== -1) {
          item.optionList = val[item.name]
        }
      }
    },
    getRegionList() {
      if (this.getAreaList.length) {
        this.setFilterData({
          arrive_region: this.getAreaList
        }, ['arrive_region'])
      } else {
        this.$axios.post(this.$api.arriveRegionList, {}).then(res => {
          let {code, msg, data} = res;
          if (code == 200) {
            this.setFilterData({
              arrive_region: data
            }, ['arrive_region'])
            this.changeState({areaList: data})
          } else {
            this.$message.error(msg);
          }
        }).catch(ret => {
          this.$message.error(ret.msg || '服务繁忙，请稍后再试');
        });
      }
    },
    //导出
    exportExcel() {
      this.$import_excal(this.download_url || "");
    },
    sizeChange(val) {
      this.form.page_size = val;
      this.getData()
    },
    pageChange(val) {
      this.form.page_start = val;
      this.getData()
    },
    filterChange(data) {
      this.form = {...this.form, ...data};
      this.getData();
    },
    getData() {
      this.loading = true;
      this.$axios.post(this.$api.yplogisticsList, {...this.postData}).then(res => {
        let {code, msg, data} = res;
        this.loading = false;
        if (code == 200) {
          let arr = ['物流', '快递', '分拣中心']
          this.tableData = data.list.filter(item => {
            item.type_desc = arr[item.type];
            item.look = this.isDetail || true;
            return item;
          });
          this.download_url = data.download_url || ''
          this.total = data.pagination.total_count || 0;
        } else {
          this.total = 0
          this.tableData = [];
        }
      }).catch(ret => {
        this.$message.error(ret.msg || '服务繁忙，请稍后再试');
      });
    },
    tableClick(data, type) {
      if (type == 'yp') {
        this.logistics_id = data.logistics_id;
        this.receive_info = `${data.receive_communicate_name}/${data.receive_communicate_mobile}`
        this.showModel = true
        this.$axios.post(this.$api.getMatchInfo, {
          logistics_id: data.logistics_id,
        }).then(res => {
          let {code, msg, data} = res;
          if (code == 200) {
            this.ypList = data.list.map(item => {
              return item
            })
          } else {
          }
        }).catch(ret => {
          this.$message.error(ret.msg || '服务繁忙，请稍后再试');
        });
      } else {
        this.$toRoutePath({
          path: "/receive_list/receive_list_detail",
          edit: true,
          query: {logistics_id: data.logistics_id}
        });
      }
    },
  },
  mounted() {
    this.getRegionList();
    this.getData();
  },
  created() {
  }
}
</script>

<style scoped lang="less" src="@/style/government/receiveInfoManage/receiveList/index.less">

</style>
<style scoped lang="less" src="@/style/cooperate/catalog/catalogList/index.less">

</style>
